package DomainObject;

import java.io.Serializable;
import java.util.ArrayList;

import org.omg.PortableServer.POA;

import Combat5.Server;
import ca.etsmtl.log720.lab1.CollectionInfractionPOA;
import ca.etsmtl.log720.lab1.Infraction;
import ca.etsmtl.log720.lab1.InfractionHelper;
//create by martin souliere
@SuppressWarnings("serial")
public class CollectionInfractionImpl extends CollectionInfractionPOA implements Serializable{

	private ArrayList<InfractionImpl> _infractions;
	public CollectionInfractionImpl() {
		_infractions = new ArrayList<InfractionImpl>();
	}
	public CollectionInfractionImpl(int[] listInfractionID, ArrayList<InfractionImpl> infractions) {
		_infractions = new ArrayList<InfractionImpl>();
		for (int i = 0; i < listInfractionID.length; i++) {
			for (int j = 0; j < infractions.size(); j++) {
				if (infractions.get(j).id() == listInfractionID[i]) {
					_infractions.add(infractions.get(j));
					break;
				}
			}
		}
	}
	public Infraction getInfraction(int index) {
		try {
			// Trouver l'infraction correspondant au parametre "index"
			InfractionImpl infraction = _infractions.get(index);

			// REcuperer le POA cree dans le serveur
			POA rootpoa = Server._poa;

			// Activer l'objet et retourner l'objet CORBA
			org.omg.CORBA.Object obj = rootpoa.servant_to_reference(infraction);

			// Retourner un infraction
			return InfractionHelper.narrow(obj);
		} catch (Exception e) {
			return null;
		}
	}

	public int size() {
		return _infractions.size();
	}
	public ArrayList<InfractionImpl> getListeInfractions() {
		return _infractions;
	}

}
